/*
  Author: xiaokai 
        - email: xiaokai.c@foxmail.com 
        - gitee: https://gitee.com/xiaokaiC
*/


#include "seq_stack.h"
#include "string.h"
#include "stdio.h"



void seq_stack_clean(seq_stack_t * stack){
	  stack->top = 0;
}

unsigned char is_seq_stack_full(seq_stack_t * stack) {
    if (stack->top / stack->cell_len >=  stack->max_len) {
		    return 1;
		} else return 0;
}

unsigned char is_seq_stack_empty(seq_stack_t * stack) {
		if (stack->top <= 0) {
		   return 1;
		} else return 0;
}

unsigned int get_seq_statck_length(seq_stack_t * stack) {
    return stack->top/stack->cell_len;
}


unsigned char seq_stack_push(seq_stack_t * stack, void * data) {
    if (is_seq_stack_full(stack) == 1) {
		    return 0;
		}
		memcpy(stack->data+stack->top, data,stack->cell_len);
		stack->top += stack->cell_len;
		return 1;
}

unsigned char seq_stack_pop(seq_stack_t * stack, void * data) {
   if (is_seq_stack_empty(stack) == 1) {
	     return 0;
	 }
	 stack->top -= stack->cell_len;
	 memcpy(data, stack->data+stack->top, stack->cell_len);
	 return 1;
}

unsigned char seq_stack_top(seq_stack_t * stack, void * data) {
   if (is_seq_stack_empty(stack) == 1) {
	     return 0;		   
	 }
	 memcpy(data, stack->data + stack->top - stack->cell_len, stack->cell_len);
	 return 1;
}




